package com.xing.asm.jtrace;

import java.util.ArrayList;
import java.util.List;

public class AdviceInvoker implements IAdvice{

    private List<IAdviceListener> listeners = new ArrayList<IAdviceListener>();

    public AdviceInvoker(List<IAdviceListener> listeners) {
        this.listeners.addAll(listeners);
    }

    public void onBegin(Object[] args) {
        for(IAdviceListener listener : listeners) {
            listener.onBegin(args);
        }
        System.err.println("onBegin");
    }

    public void onReturn(Object obj) {
        for(IAdviceListener listener : listeners) {
            listener.onReturn(obj);
        }
        System.err.println("onReturn");
    }

    public void onThrow(Throwable thr) {
        for(IAdviceListener listener : listeners) {
            listener.onThrow(thr);
        }
        System.err.println("onThrow");
    }

    public void onInvoke(Integer lineNumber, String own, String name, String desc, boolean itf) {
        for(IAdviceListener listener : listeners) {
            listener.onInvoke(lineNumber, own, name, desc, itf);;
        }
        System.err.println("onInvoke");
    }
}
